package com.mstore.service;

import java.util.ArrayList;
import java.util.List;
import com.mstore.dao.SMSLogDao;
import com.mstore.pojo.SMSLog;

public class SMSLogService {

	private SMSLogDao smsLogDao;

	/**
	 * 
	 * 保存短信发送记录
	 */
	public void addSMSLog(SMSLog smsLog) {
		smsLogDao.save(smsLog);
	}

	/**
	 * 
	 * 查询所有短信发送记录
	 */
	public List<SMSLog> watchSMSLog(SMSLog smsLog) {
		List<SMSLog> smsLogs = new ArrayList<SMSLog>();
		List<Object> objects = smsLogDao.watchSMSLog(smsLog);
		for (Object object : objects) {
			SMSLog log = new SMSLog();
			log = (SMSLog) object;
			log.setCreateTime(log.getCreateTime().substring(0,
					log.getCreateTime().indexOf(".")));
			smsLogs.add(log);
		}
		return smsLogs;
	}


	//分页方法
	
	public List<SMSLog> getList(SMSLog smsLog,int index){
		
		List<SMSLog>smsLogs=new ArrayList<SMSLog> ();
		List<Object> objects=smsLogDao.getList(smsLog, index);
		
		for (Object object : objects) {
			SMSLog sms=(SMSLog) object;
			sms.setCreateTime(sms.getCreateTime().substring(0, sms.getCreateTime().indexOf(".")));
			smsLogs.add(sms);
		}
		return smsLogs;
	}
	
	public int getCount(){
		return smsLogDao.getCount();
	}

	public SMSLogDao getSmsLogDao() {
		return smsLogDao;
	}

	public void setSmsLogDao(SMSLogDao smsLogDao) {
		this.smsLogDao = smsLogDao;
	}

}
